#include <iostream>
#include <fstream>
using namespace std;
#include "network.h"
#include "NODES.h"

NODES::NODES() {
    N=0;
    DOF=0;
    STATE=NULL;
    }

void NODES::CREATE(int n,int dof) {
    N=n;
    DOF=dof;
    STATE=new double*[DOF];
    for(int i=0; i<DOF; i++) STATE[i]=new double[N];
    }

NODES::NODES(NODES   &node) {
    N=node.N;
    DOF=node.DOF;
    STATE=new double*[DOF];
    for(int i=0; i<DOF; i++) {
        STATE[i]=new double[N];
        for(int j=0; j<N; j++)  STATE[i][j]=node.STATE[i][j];
        }
    }

NODES::~NODES() {
    if(!N) return;
    for(int i=0; i<DOF; i++) delete STATE[i];
    delete STATE;
    NODES();
    }

void NODES::initial(char tag,  double *para) {
    switch (tag) {
        case '0':
            for(int i=0; i<DOF; i++) {
                STATE[i]=new double[N];
                for(int j=0; j<N; j++)  STATE[i][j]=0;
                }
            break;
        case 't':
            STATE[0][0]=0;
            STATE[0][1]=STATE[0][2]=1;
            break;
        }
    }


void NODES::print_state() {
    for(int i=0; i<N; i++) {
        cout<<"node"<<i<<"    ";
        for(int j=0; j<DOF; j++)  cout<<"DOF"<<j<<":"<<STATE[j][i]<<"  ; ";
        cout<<endl;
        }
    }

void NODES::print_state(ofstream &File,char tag) {
    switch (tag) {
        case '0':
            for(int i=0; i<N; i++)
                for(int j=0; j<DOF; j++)  File<<STATE[j][i]<<";";
            File<<endl;
            break;
        case 's':
            for(int i=0; i<N; i++)  File<<STATE[0][i]<<";";
            File<<endl;
            break;
        }
    }
